package com.myblog.controller;


import com.myblog.common.lang.Result;
import com.myblog.entity.Message;
import com.myblog.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author From:星羽恒
 * @since 2021-11-24
 */
@RestController
@RequestMapping("/message")
public class MessageController {
    @Autowired
    MessageService messageService;

    @GetMapping("")
    public Result getMessages(){
        List<Message> messages = messageService.list();
        return Result.succ(messages);
    }

    @PostMapping("/add")
    public Result addMessage(@RequestBody Message newMessage){
        messageService.save(newMessage);
        return Result.succ(newMessage);
    }
}
